import {
  createStore
} from 'vuex'
import {
  login
} from '../api/api.js';

export default createStore({
  state: {
    user: {
      isLogin: false,
      userInfo: {}
    }
  },
  getters: {

  },
  mutations: {
    setUser: function (state, value) {
      state.user = value
    }
  },
  actions: {
    async loginUser(content, payload) {
      let result = await login(payload.email, payload.password);
      // console.log(result);
      if (result.data.state == "OK") {
        content.state.user.isLogin = true;
        content.state.user.userInfo = result.data.userInfo;
        localStorage.user = JSON.stringify(content.state.user);
        content.commit('setUser', content.state.user);
      }
      // console.log(result);
      return result
    }
  },
  modules: {}
})